home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / FileClass.h < prev    next >
Encoding:
Text File  |  1993-01-14  |  5.5 KB  |  162 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992-93 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Programmer: Kent Sandvik
  5.   Date: 12/27/92
  6.   Revision comments are at the end of this file.
  7.   ---
  8.   TFile is a simple object that does file manipulations    
  9.   TFile.h contains the TFile class and subclass definitions. 
  10.   _________________________________________________________________________________________________________ */
  11.  
  12. // Declare label for this header file
  13. #ifndef _FILECLASS_
  14. #define _FILECLASS_
  15.  
  16. #ifndef _DTSCPLUSLIBRARY_
  17. #include "DTSCPlusLibrary.h"
  18. #endif
  19.  
  20. #ifndef __FILES__
  21. #include <Files.h>
  22. #endif
  23.  
  24. #ifndef __OSUTILS__
  25. #include <OSUtils.h>
  26. #endif
  27.  
  28. #ifndef __RESOURCES__
  29. #include <Resources.h>
  30. #endif
  31.  
  32. // globals
  33. const OSType kDefaultCreator = '????';
  34. const OSType kDefaultType = 'TEXT';
  35. const SignedByte kExclusiveReadWrite = 0;
  36. const long kNoOffset = 0L;
  37.  
  38. // _________________________________________________________________________________________________________ //
  39. //    TFile Class Interface.
  40. class TFile
  41. // Basic File class for file I/O handling.
  42. {
  43. public:
  44.     // CONSTRUCTORS AND DESTRUCTORS
  45.     TFile(char* name = "UnTitled");                    // define file based on name (current folder)
  46.     TFile(FSSpec theSpec);                            // define file based on FSSpec
  47.     TFile(short volume,                                // define file based on volume, dirID and name (FSSpec)
  48.           long dirID,
  49.           Str63 name);
  50.  
  51.     virtual~ TFile();                                // default destructor                        
  52.  
  53.     virtual void Initialize();                        // initialize fields to known values
  54.  
  55.     // MAIN INTERFACE
  56.     virtual Boolean Create();                        // create a file
  57.     virtual Boolean Rename(char* newName);            // rename the file
  58.     virtual void Delete();                            // delete the file
  59.     virtual Boolean FileExists();                    // check if file exists
  60.     virtual Boolean Open(SignedByte permission) = 0;// open file
  61.     virtual Boolean Close() = 0;                    // close file
  62.  
  63.     // ACCESSORS AND MUTATORS
  64.     virtual void SetType(const OSType creator,        // define file type and creator
  65.                          const OSType fileType);
  66.     virtual void SetFileName(const Str63 fileName);    // set name of file
  67.     virtual FInfo GetFileInfo();                    // get file information frome the specific file
  68.  
  69.     // FIELDS
  70. protected:
  71.     FSSpec fFileSpec;                                // the generic container for File information
  72.     OSType fFileType;                                // type of file
  73.     OSType fCreator;                                // creator of file
  74.     Boolean fOpened;                                // keep track if the file is open or not
  75.     Boolean fFlushing;                                // should we flush after each file operation?
  76.     short fRefNum;                                    // reference number to the file
  77.     OSErr fError;                                    // latest error
  78. };
  79.  
  80.  
  81. // _________________________________________________________________________________________________________ //
  82. //    TDataFile Class Interface.
  83. class TDataFile : public TFile
  84. // TData file is a file that uses mainly the data fork of the file.
  85. {
  86. public:
  87.     // CONSTRUCTORS AND DESTRUCTORS
  88.     TDataFile(char* name = "UnTitled");                // default constructor
  89.     ~TDataFile();                                    // default destructor
  90.  
  91.     // MAIN INTERFACE
  92.     virtual Boolean Open(SignedByte permission = kExclusiveReadWrite);// exclusive read/write permission
  93.     virtual Boolean Close();                        // close the file
  94.     virtual Boolean WriteHandle(Handle h);            // write handle into disk
  95.     virtual Handle ReadHandle();                    // read handle from disk
  96.     virtual Boolean Write(Ptr buffer,
  97.                           long bytes);                // write bytes to disk from current mark
  98.     virtual Boolean Read(Ptr buffer,
  99.                          long bytes);                // read bytes from disk at current mark
  100.     virtual Boolean SetMark(short from,
  101.                             long offset);            // set offset of mark
  102.     virtual long GetMark();                            // get offset
  103.     virtual Boolean Reset();                        // set file mark to beginning of file
  104.     virtual Boolean GotoEndOfFile();                // set file mark at end of file 
  105. };
  106.  
  107. // _________________________________________________________________________________________________________ //
  108. //    TResourceFile Class Interface.
  109. class TResourceFile : public TFile
  110. // TResourceFile uses mainly the resource fork of the file.
  111. {
  112. public:
  113.     // CONSTRUCTORS AND DESTRUCTORS
  114.     TResourceFile(char* name = "UnTitled");            // default constructor
  115.     ~TResourceFile();                                // default destructor
  116.  
  117.     // MAIN INTERFACE
  118.     virtual Boolean Create();                        // create a file
  119.     virtual Boolean Open(SignedByte permission = kExclusiveReadWrite);    // open the file
  120.     virtual Boolean Close();                        // close the file
  121.  
  122.     virtual Boolean HasResourceFork();                // test if file has resource fork or not
  123.     virtual void Update();                            // update the file
  124.     virtual void Assign();                            // assign the file to the first one in the resource chain
  125. };
  126.  
  127.  
  128. // _________________________________________________________________________________________________________ //
  129. //    MPreferences Class Interface.
  130. class MPreferences
  131. // Find and create files in the preferences section of the hard disk (future)
  132. {
  133. public:
  134. };
  135.  
  136.  
  137. // _________________________________________________________________________________________________________ //
  138. //    MTempFile Class Interface.
  139. class MTempFile
  140. // Find and create files in the temp section of the hard disk (future)
  141. {
  142. public:
  143. };
  144.  
  145.  
  146. // _________________________________________________________________________________________________________ //
  147. //    TLogFile Class Interface.  (future)
  148. class TLogFile : public TFile
  149. {
  150. public:
  151. };
  152.  
  153.  
  154. #endif
  155.  
  156. // _________________________________________________________________________________________________________ //
  157. /*    Change History (most recent last):
  158.   No        Init.    Date        Comment
  159.   1            khs        12/27/92    New file
  160.   2            khs        1/14/93        Cleanup
  161. */
  162.